package pers.cz.session;

import com.alibaba.fastjson.JSON;

/**
 * @program: PostGirl-panent
 * @description: UserUtils
 * @author: Cheng Zhi
 * @create: 2023-01-18 18:33
 **/
public class UserUtils {

    /**
     * 获取用户编号
     * @return
     */
    public static Integer getUserId() {
        User user = ContextHolder.getRequestContext().get("userInfo");
        Integer userId = user.getUserId();
        return userId;
    }

    /**
     * 获取用户名称, todo 目前未设置用户名，所哟获取到的一定时空，使用时先set
     * @return
     */
    public static String getUserName() {
        User user = ContextHolder.getRequestContext().get("userInfo");
        return user.getUserName();
    }

    public static void setUserId(Integer userId) {
        User user = new User();
        user.setUserId(userId);
        ContextHolder.getRequestContext().put("userInfo", user);
    }
}
